using HKB.Common;
using System;
using System.Data;
using System.Web;
namespace HKB.Web
{
	public class OnlinePaySeting
	{
		private Conn conn;
		public OnlinePaySeting()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public OnlinePaySeting(Conn _conn)
		{
			this.conn = _conn;
		}
		public DataTable Getall()
		{
			return this.conn.GetDataTable("Select * From HL_OnlinePaySeting");
		}
		public DataTable GetPaySetingByID(int ID)
		{
			return this.conn.GetDataTable("Select * From HL_OnlinePaySeting Where ID=" + ID);
		}
		public bool updateByUserID(int userID, string PayTitle, string MerID, string MerKey, string MerName)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@PayTitle", DbType.String, PayTitle),
				this.conn.CreateParameter("@MerID", DbType.String, MerID),
				this.conn.CreateParameter("@MerKey", DbType.String, MerKey),
				this.conn.CreateParameter("@MerName", DbType.String, MerName),
				this.conn.CreateParameter("@userID", DbType.Int32, userID)
			};
			return this.conn.Execute("Update [HL_OnlinePaySeting] Set PayTitle=@PayTitle, MerID=@MerID, MerKey=@MerKey, MerName=@MerName Where userID=@userID", parameters) == 1;
		}
		public bool AddByUserID(string PayTitle, string MerID, string MerKey, string MerName, int isOpen, string SysStr, int userID)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@PayTitle", DbType.String, PayTitle),
				this.conn.CreateParameter("@MerID", DbType.String, MerID),
				this.conn.CreateParameter("@MerKey", DbType.String, MerKey),
				this.conn.CreateParameter("@MerName", DbType.String, MerName),
				this.conn.CreateParameter("@isOpen", DbType.Int32, isOpen),
				this.conn.CreateParameter("@SysStr", DbType.String, SysStr),
				this.conn.CreateParameter("@userID", DbType.Int32, userID)
			};
			return this.conn.Execute("INSERT INTO [HL_OnlinePaySeting](PayTitle,MerID,MerKey,MerName,isOpen,SysStr,userID) VALUES(@PayTitle,@MerID,@MerKey,@MerName,@isOpen,@SysStr,@userID)", parameters) == 1;
		}
		public bool updateUserID(int userID)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@userID", DbType.Int32, userID)
			};
			return this.conn.Execute("update [HL_OnlinePaySeting] set userID=@userID Where userID=@userID", parameters) == 1;
		}
		public DataTable GetPaySetingByUserID(int userID)
		{
			return this.conn.GetDataTable("Select * From HL_OnlinePaySeting Where userID='" + userID + "'");
		}
		public DataTable GetPaySetingByPartnerID(string partnerStr)
		{
			return this.conn.GetDataTable("Select * From HL_OnlinePaySeting Where MerID='" + partnerStr + "'");
		}
		public DataTable GetPaySetingByPartnerByEmail(string email)
		{
			return this.conn.GetDataTable("Select * From HL_OnlinePaySeting Where MerName='" + email + "'");
		}
		public DataTable GetActivePaySeting(string key)
		{
			return this.conn.GetDataTable("Select * From HL_OnlinePaySeting Where MerKey='" + key + "'");
		}
		public T GetFieldByID<T>(string Field, int ID)
		{
			return (T)((object)this.conn.GetScalar(string.Concat(new object[]
			{
				"Select ",
				Field,
				" From HL_OnlinePaySeting Where ID=",
				ID
			}), new IDbDataParameter[0]));
		}
		public bool Add(string PayTitle, string MerID, string MerKey, string MerName, int isOpen, string SysStr)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@PayTitle", DbType.String, PayTitle),
				this.conn.CreateParameter("@MerID", DbType.String, MerID),
				this.conn.CreateParameter("@MerKey", DbType.Int32, MerKey),
				this.conn.CreateParameter("@MerName", DbType.String, MerName),
				this.conn.CreateParameter("@isOpen", DbType.Int32, isOpen),
				this.conn.CreateParameter("@SysStr", DbType.String, SysStr)
			};
			return this.conn.Execute("INSERT INTO [HL_OnlinePaySeting](PayTitle,MerID,MerKey,MerName,isOpen,SysStr) VALUES(@PayTitle,@MerID,@MerKey,@MerName,@isOpen,@SysStr)", parameters) == 1;
		}
		public bool Update(int ID, string PayTitle, string MerID, string MerKey, string MerName)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@PayTitle", DbType.String, PayTitle),
				this.conn.CreateParameter("@MerID", DbType.String, MerID),
				this.conn.CreateParameter("@MerKey", DbType.String, MerKey),
				this.conn.CreateParameter("@MerName", DbType.String, MerName)
			};
			return this.conn.Execute("Update [HL_OnlinePaySeting] Set PayTitle=@PayTitle, MerID=@MerID, MerKey=@MerKey, MerName=@MerName Where ID=" + ID, parameters) == 1;
		}
		public bool SetActive(int ID, int isOpen)
		{
			return this.conn.Execute(string.Concat(new object[]
			{
				"Update [HL_OnlinePaySeting] Set isOpen=",
				isOpen,
				" Where ID=",
				ID
			})) == 1;
		}
		public bool DelPaySeting(int ID)
		{
			return this.conn.Execute("Delete From HL_OnlinePaySeting Where ID=" + ID) == 1;
		}
	}
}
